package com.example.springboot_shopsystem01.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.springboot_shopsystem01.domain.Good;
import com.example.springboot_shopsystem01.domain.Staff;
import com.example.springboot_shopsystem01.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/good")
public class GoodController {
    @Autowired
    private GoodService goodService;

    @GetMapping
    public List<Good> getAll(){
        return goodService.getAll();
    }

    @PostMapping
    public Boolean save(@RequestBody Good good){  //通过请求体 传json数据过来
        System.out.println(good);
        return goodService.save(good);
    }

    @PutMapping
    public Boolean update(@RequestBody Good good){
        return goodService.update(good);
    }

    @DeleteMapping("{id}")   // 通过路径传参
    public boolean delete(@PathVariable Integer id){
        return goodService.delete(id);
    }

    @GetMapping("{id}")
    public Good getById(@PathVariable Integer id){
        return goodService.getById(id);
    }

    @GetMapping("{currentPage}/{pageSize}")
    public IPage<Good> getPage(@PathVariable int currentPage, @PathVariable int pageSize, Good good){
        return goodService.getPage(currentPage, pageSize, good);
    }
}

